package com.sys.mapper;

import com.sys.entity.BizTaskLog;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface BizTaskLogMapper {
    @Insert("INSERT INTO biz_task_log (plan_item_id, task_id, user_id, status, score, remarks, photos_count, logged_at, create_by, create_time, update_by, update_time, remark, del_flag) " +
            "VALUES (#{planItemId}, #{taskId}, #{userId}, #{status}, #{score}, #{remarks}, #{photosCount}, #{loggedAt}, #{createBy}, #{createTime}, #{updateBy}, #{updateTime}, #{remark}, COALESCE(#{delFlag}, 0))")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void save(BizTaskLog log);

    @Select("SELECT * FROM biz_task_log " +
            "WHERE user_id = #{userId} " +
            "AND logged_at BETWEEN #{startTime} AND #{endTime} " +
            "AND del_flag = 0 " +
            "ORDER BY logged_at DESC")
    List<BizTaskLog> findByUserIdAndDateRange(@Param("userId") Long userId,
            @Param("startTime") LocalDateTime startTime,
            @Param("endTime") LocalDateTime endTime);
}